package com.wilmer.dynamic.controller;

import com.wilmer.common.annotation.Anonymous;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.core.page.TableDataInfo;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.dynamic.domain.SysDynamic;
import com.wilmer.dynamic.service.ISysDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 园内动态Controller
 *
 * @author 修改人hans
 * @date 2024-04-24
 */
@Api(tags = {"园内动态接口"})
@RestController
@RequestMapping("/dynamic/dynamic")
public class SysDynamicController extends BaseController
{
    @Autowired
    private ISysDynamicService sysDynamicService;

    /**
     * 查询园内动态列表
     */
    @ApiOperation("查询园内动态列表")
    @GetMapping("/list")
    public TableDataInfo list(SysDynamic sysDynamic)
    {
        startPage();
        List<SysDynamic> list = sysDynamicService.selectSysDynamicList(sysDynamic);
        return getDataTable(list);
    }

    /**
     * 导出园内动态列表
     */
    @ApiOperation("导出园内动态列表")
    @Log(title = "园内动态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDynamic sysDynamic)
    {
        List<SysDynamic> list = sysDynamicService.selectSysDynamicList(sysDynamic);
        ExcelUtil<SysDynamic> util = new ExcelUtil<SysDynamic>(SysDynamic.class);
        util.exportExcel(response, list, "园内动态数据");
    }

    /**
     * 获取园内动态详细信息
     */
    @ApiOperation("获取园内动态详细信息")
    @GetMapping(value = "/{dynamicId}")
    public AjaxResult getInfo(@PathVariable("dynamicId") Long dynamicId)
    {
        return success(sysDynamicService.selectSysDynamicByDynamicId(dynamicId));
    }

    /**
     * 新增园内动态
     */
    @ApiOperation("新增园内动态")
    @Log(title = "园内动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDynamic sysDynamic)
    {
        return toAjax(sysDynamicService.insertSysDynamic(sysDynamic));
    }

    /**
     * 修改园内动态
     */
    @ApiOperation("修改园内动态")
    @Log(title = "园内动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDynamic sysDynamic)
    {
        return toAjax(sysDynamicService.updateSysDynamic(sysDynamic));
    }

    /**
     * 删除园内动态
     */
    @ApiOperation("删除园内动态")
    @Log(title = "园内动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dynamicIds}")
    public AjaxResult remove(@PathVariable Long[] dynamicIds)
    {
        return toAjax(sysDynamicService.deleteSysDynamicByDynamicIds(dynamicIds));
    }
    /**
     * 统计问题反馈数量
     */
    @ApiOperation("统计问题反馈数量")
    @GetMapping("/count")
    public int count(@RequestParam("deptId") Long deptId)
    {
        int count = sysDynamicService.sysDynamicCount(deptId);
        return count;
    }
}
